package com.server.server_a10.controller.lightingSystem;


import com.server.server_a10.entity.Inform;
import com.server.server_a10.entity.lightingSystem.Light;
import com.server.server_a10.mapper.LightMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@Api("前后交互的测试用例")
public class LightHandle {

    @Autowired
    LightMapper lightMapper;

    @GetMapping(value = "/oneLightInf")
    @ApiOperation("这个接口是单个照明设备的测试接口，入参为设备id，回参为设备信息，" +
            "目前不论id为多少，只要传了id就会返回信息")
    public Light getOneLightDemo(String id){
        return new Light(10001L,10001L,10001L,"demoLight",true);
    }

    @PostMapping(value = "/getLightsByRoomId")
    public Inform getLightByRoomId(@RequestBody Map<String,Object> request){
        Inform inform = new Inform();
        int id = (int) request.get("id");

        List<Light> lights = lightMapper.getLightByRoomId(id);
        if (lights.isEmpty()){
            inform.setCode(100);
            inform.setMsg("这个房间没有灯");
        }else {
            inform.setCode(200);
            inform.setMsg("此房间的灯已加载完毕！");
            inform.setData(lights);
        }

        return inform;
    }
}
